/*
 * Copyright (c) 1990, 2022, shwfed and/or its affiliates. All rights reserved.
 *
 * @date: 2022-08-24
 *
 */
package cn.junglead.common.utils;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * 编码工具类，注意BASE64是编码工具，不是加解密工具
 *
 * @author Gary.Wang
 * @version 1.0
 */
public final class CodeUtil {

    /**
     * BASE64编码
     * @param plaintext 明文
     * @return 返回编码后的结果
     */
    public static String BASE64Code(String plaintext){
        return Base64.getEncoder().encodeToString(plaintext.getBytes(StandardCharsets.UTF_8));
    }

    /**
     * BASE64解码
     * @param ciphertext 密文
     * @return 返回解码后的结果
     */
    public static String BASE64Decode(String ciphertext){
        byte[] decode = Base64.getDecoder().decode(ciphertext);
        return new String(decode, StandardCharsets.UTF_8);
    }
}
